<template>
  <el-container class="home-container">
    <!-- 头部区域   -->
    <el-header>
      <div>
        <span>问卷管理系统</span>
        <el-menu :default-active="activePath" active-text-color="#409eff" mode="horizontal" router>
          <!-- <el-menu-item index="/user" @click="saveNavState('/user')">用户管理</el-menu-item>
          <el-menu-item index="/new" @click="saveNavState('/new')">问卷新建</el-menu-item> -->
          <el-menu-item index="/questionnaire" @click="saveNavState('/questionnaire')">问卷管理</el-menu-item>
          <el-menu-item index="/recyclebin" @click="saveNavState('/recyclebin')">回收站</el-menu-item>
          <!-- <el-submenu index="/data">
            <template slot="title">数据统计</template>
            <el-menu-item index="/1" @click="saveNavState('/1')">选项1</el-menu-item>
            <el-menu-item index="/2" @click="saveNavState('/2')">选项2</el-menu-item>
            <el-menu-item index="/3" @click="saveNavState('/3')">选项3</el-menu-item>
          </el-submenu> -->
        </el-menu>
      </div>
      <el-button type="text" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主题区域 -->
    <el-container>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data () {
    return {
      // 被激活的链接地址
      activePath: ''
    }
  },
  created () {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 保存链接的激活状态
    saveNavState (activePath) {
      // console.log(activePath)
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
  }
}
.el-main {
  background-color: #e9eef3;
}
</style>
